<template>
  <el-drawer :visible.sync="visible" :title="title" :modal-append-to-body="true" :append-to-body="true"
    :destroy-on-close="false" :modal="true" direction="rtl" :wrapperClosable="false" custom-class="form-drawer"
    size="450px" @closed="closed">
    <div class="form-drawer__content">
      <!-- <el-form :inline="true" :model="queryForm" class="demo-form-inline">
        <el-form-item style="margin-bottom:10px;">
          <el-input v-model="queryForm.keywords" prefix-icon="el-icon-search" placeholder="POI名称" style="width: 14.5rem"
            @input="onQuerySubmit" />
        </el-form-item>
      </el-form> -->
      <el-table :data="tableData" border empty-text="暂无数据." style="width: 100%">
        <el-table-column type="index" label="序号" width="50" align="center" :index="indexMethod">
        </el-table-column>

        <el-table-column prop="status" label="图标" width="150px" align="center">
          <template slot-scope="scope">
            <el-image style="width: 120px; height: 90px" fit="fit" :src="scope.row.url">
            </el-image>
          </template>
        </el-table-column>

        <el-table-column prop="markerNormalSize" label="图标尺寸">
        </el-table-column>

        <el-table-column label="操作" width="130" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleAdd(scope.row)">创建样式
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- <el-row>
        <el-col :span="24">
          <div align="right" style="margin-top: 0.3125rem;">
            <el-pagination background layout="prev, pager, next" :current-page="page.cur" :page-size="page.limit"
              :total="page.total" @current-change="handleCurrentChange" />
          </div>
        </el-col>
      </el-row> -->
      <div style="text-align: right;padding-top: 0.3125rem;padding-bottom: 0.3125rem;">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page.cur"
          :page-size="page.limit" :total="page.total" :page-sizes="[10, 20, 30, 40]"
          layout="prev, pager, next, total, sizes">
        </el-pagination>
      </div>

    </div>
  </el-drawer>
</template>

<script>
  /* import InfoDrawer from './components/InfoDrawer.vue' */
  import {
    findPoiStyleList,
  } from '@/api/subsystem/poiTemplate'
  import {
    addPoiStyle,
  } from '@/api/subsystem/layer'
  import {
    isOk
  } from '@/utils/request'
  export default {
    name: 'TemplateInfo',
    components: {
      // InfoDrawer,
    },
    props: {
      properties: {
        type: Object,
        default: () => ({})
      }
    },
    computed: {},
    watch: {
      properties: {
        handler: function(value) {
          this.visible = value.visible
          this.layerId = value.layerId
        },
        immediate: true,
        deep: false
      }
    },
    data() {
      return {
        loading: false,
        visible: false,
        layerId: '',
        baseUrl: process.env.VUE_APP_BASE_API,
        title: 'POI模板信息',
        queryForm: {
          keywords: undefined,
        },
        page: {
          cur: 1,
          limit: 50,
          total: 0
        },
        tableData: [],
      }
    },
    created() {
      this.load()
    },
    methods: {
      indexMethod(index) {
        return index + 1;
      },
      onQuerySubmit(event) {
        this.load()
      },
      onReset(event) {
        this.queryForm.keywords = undefined;
        this.queryForm.status = '';
        this.load()
      },
      load() {
        this.loading = true
        findPoiStyleList({
            projectId: this.$store.getters.projectId,
            cur: this.page.cur,
            limit: this.page.limit,
            keywords: this.queryForm.keywords,
          }).then(rsp => {
            if (isOk(rsp)) {
              const _data = rsp.result
              this.page.total = _data.totalRow
              _data.list.forEach(item => {
                item['url'] = this.baseUrl + '/biz/scene/thumbnail/' + item.id + '_normal'
              })
              this.tableData = _data.list
              this.loading = false
            }
          }).catch(err => {
            console.log(err);
          })
          .finally(() => {
            this.loading = false
          })
      },
      handleSizeChange(val) {
        this.page.limit = val
        this.load()
      },
      handleCurrentChange(cur) {
        this.page.cur = cur
        this.load()
      },
      handleAdd: function(e) {
        addPoiStyle({
          templateId: e.id,
          layerId: this.layerId
        }).then(rsp => {
          if (isOk(rsp)) {
            this.closed()
            this.opend(rsp.result, this.layerId)
          }
        })
        // this.editDrawer.visible = true
        // this.editDrawer.type = '0'
      },
      closed: function() {
        this.$emit('closed', false)
      },
      opend: function(e, id) {
        this.$emit('opend', e, id)
      },
    }
  }
</script>
<style scoped>
  /deep/.el-card__header {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  /deep/.layer-card .el-card__body {
    padding: 5px;
  }

  /deep/.form-drawer__content form,
  .form-drawer__footer button {
    flex: none;
  }
</style>
